Field of the Invention
The present invention relates to an image processing method for performing pattern matching based on a shape using a coarse-to-fine search method, an image processing apparatus, and a recording medium.
Description of the Related Art
In general, in a field of image processing, pattern matching has been widely used as a method for detecting an object (a work) and measuring a position of the object. In particular, pattern matching based on a shape has been widely used since a degree of similarity is calculated only using a portion including a feature of a shape in an image, and therefore, the shape pattern matching is performed at high speed.
In the shape pattern matching, a degree of similarity is calculated using features of shapes of a reference image obtained by capturing a work in an ideal state and a search target image obtained by capturing a target work, and therefore, extraction of the features of shapes from the images is required. As a method for extracting an edge as a shape feature, a method using an edge extraction filter, such as a Sobel filter or a Canny filter, is widely used.
Specifically, the shape pattern matching is a method for generating a model edge using a reference image and a search target edge using a search target image by performing the edge extraction method described above on the reference image and the search target image and for calculating a degree of similarity between the model edge and the search target edge.
An edge is a portion in which a luminance gradient between pixels is large, and is actually a group of edge points. Specifically, a group of edge points arranged in accordance with an arbitrary rule is referred to as an “edge”. In general, an edge formed by connecting adjacent edge points to one another is widely used. Since an edge is formed by edge points, image processing using features of the edge may be performed. For example, a feature value, such as an edge size, may be calculated.
As a method for realizing high-speed pattern matching, a coarse-to-fine search method is used. In the coarse-to-fine search method, a rough position is detected using data of a small information amount, and thereafter, a detailed position is detected using data of a large information amount. In practice, first, a process of generating an image of a low resolution by reducing a size of an image of a high resolution is repeatedly performed so that different images of different low resolutions are generated. Subsequently, pattern matching is performed on an image having a lowest resolution so that a rough position of a work is detected. Thereafter, the search is performed only on a range in the vicinity of a preceding detection position in an image of a resolution higher than that of a preceding image so that a detection position may be gradually obtained with higher accuracy. Note that the size reduction may be performed not only on an image but also on a region including an edge to be extracted (hereinafter referred to as an “edge extraction region”), a region including a work to be searched for (hereinafter referred to as “search region”), and an edge.
In general, in a case where the coarse-to-fine search method is employed, an edge of a low resolution is also taken into consideration, and therefore, it is difficult to select an edge to be used as a model and to control parameters. If the size reduction is performed without taking a degree of a feature into consideration, there arises a problem in that an edge having a feature of a small degree blurs and becomes unstable due to environmental influence, and as a result, a detection of a work fails. Furthermore, if the size reduction which causes a blur of an edge is not performed taking a size of an edge into consideration, the coarse-to-fine search method may not be sufficiently performed at high speed.
To address this problem, Japanese Patent Laid-Open No. 2010-97438 proposes a method for determining a size reduction factor of image data in accordance with a degree of sharpness of an edge point. In this method, a size reduction factor based on a degree of sharpness of an edge point is set to an image so that detection is stably performed.
However, in Japanese Patent Laid-Open No. 2010-97438, a certain size reduction factor is set to an image, and therefore, if one of edge points has a low degree of sharpness, the size reduction factor suitable for the edge point is set. Accordingly, a large size reduction factor may not be set. If a large size reduction factor may not be set, processing employing the coarse-to-fine search method may not be sufficiently performed at high speed. On the other hand, even in a case where a large size reduction factor may be set since a degree of sharpness is high, if an edge is small, it is likely that the image includes am unstable edge, such as a blur of an edge described above, and accordingly, detection is unstable.